import 'package:share_fit/app/controllers/home/weather/model/weather_type.dart';
import 'package:share_fit/app/helper/ext/tr_ext.dart';
import 'package:share_fit/app/models/base_model.dart';
import 'package:share_fit/app/tools/date_tool.dart';
import 'package:share_fit/generated/locales.g.dart';

class HourlyWeatherModel extends BaseModel {
  /// 预报时间
  DateTime? date;

  /// 风向360角度
  String? wind360;

  /// 风向
  String? windDir;

  /// 风力等级
  String? windScale;

  ///  风速，公里/小时
  String? windSpeed;

  /// 相对湿度，百分比数值
  String? humidity;

  /// 逐小时预报降水概率，百分比数值，可能为空
  int? pop;

  /// 当前小时累计降水量，默认单位：毫米
  String? precip;

  /// 温度，默认单位：摄氏度
  int? temp;

  /// 温度单位：0 -> 摄氏度，1 -> 华氏度
  int? tempUnit;

  /// 天气状况的图标代码，另请参考天气图标项目
  String? icon;

  ///  天气状况的文字描述，包括阴晴雨雪等天气状态的描述
  String? text;

  /// 大气压强，默认单位：百帕
  String? pressure;

  /// 云量，百分比数值。可能为空
  String? cloud;

  HourlyWeatherModel({
    this.date,
    this.wind360,
    this.windDir,
    this.windScale,
    this.windSpeed,
    this.humidity,
    this.pop,
    this.precip,
    this.temp,
    this.tempUnit = 0,
    this.icon,
    this.text,
    this.pressure,
    this.cloud,
  });

  @override
  bool from(Map map) {
    // date = map['date'];
    // text = map['text'];
    // tempUnit = map['tempUnit'];
    // temp = _getTemperature(int.parse(map['temp']));
    return true;
  }

  @override
  toMap() {
    return {
      'timestamp': DateTool.getTimeInSeconds(date!),
      'phenomenon': WeatherType.getType(text!),
      'temperature': temp!
    };
  }

  @override
  List<Object?> get props => [date, text, temp];

  String _getTemperature(int temp) {
    if (tempUnit == 1) {
      double f = 32 + temp * 1.8;
      return '${f.round()}${LocaleKeys.temperature_unit_f.ts}';
    } else {
      return '$temp${LocaleKeys.temperature_unit_c.ts}';
    }
  }
}
